<template>
	<view class="real-container">
		<!-- 导航栏 -->
		<view class="content">
			<!-- <view class="content-item" @click="gourl('/userPage/user/settingInfo')">
				<view class="item-left">
					<text>个人信息</text>
				</view>
				<u-icon name="arrow-right" color="#D1D1D1" size="28"></u-icon>
			</view> -->
			<u-gap height="18" bg-color="#262626"></u-gap>
			<view class="content-item" @click="gourl('/userPage/user/account')">
				<view class="item-left">
					<text>账号与安全</text>
				</view>
				<u-icon name="arrow-right" color="#fff" size="28"></u-icon>
			</view>
			<u-gap height="18" bg-color="#262626"></u-gap>

			<view class="content-item" @click="gourl('/userPage/user/address/address')">
				<view class="item-left">
					<text>地址管理</text>
				</view>
				<u-icon name="arrow-right" color="#fff" size="28"></u-icon>
			</view>
			<u-gap height="18" bg-color="#262626"></u-gap>
			<!-- #ifdef APP-PLUS -->
			<view class="content-item" @click="clearStorage">
				<!-- <view> -->
					<view  class="item-left" style="color:white;">
						<view>清除缓存</view>
					</view>
					<view  style="color:white;">{{ currentSize }}</view>
					
				<!-- </view> -->
				<u-icon name="arrow-right" color="#fff" size="28"></u-icon>
			</view>
			<u-gap height="18" bg-color="#262626"></u-gap>
			<!-- #endif -->


			<view class="content-item" @click="gourl('/userPage/user/guanyu?type=1&id=1')">
				<view class="item-left">
					<text>关于我们</text>
				</view>
				<u-icon name="arrow-right" color="#fff" size="28"></u-icon>
			</view>
			<u-gap height="18" bg-color="#262626"></u-gap>
			<!-- <u-line color="#CECECE" length="95%" margin="20rpx" />
			<view class="content-item" @click="gourl('/userPage/user/agreement?type=1&id=2')">
				<view class="item-left">
					<text>用户协议</text>
				</view>
				<u-icon name="arrow-right" color="#D1D1D1" size="28"></u-icon>
			</view>
			<u-line color="#CECECE" length="95%" margin="20rpx" />

			<view class="content-item" @click="gourl('/userPage/user/agreement?type=1&id=3')"
				style="border-bottom: none">
				<view class="item-left">
					<text>隐私政策</text>
				</view>
				<u-icon name="arrow-right" color="#D1D1D1" size="28"></u-icon>
			</view>
			<u-gap height="18" bg-color="#F9FAFC"></u-gap> -->
		</view>
		<view class="foot_btn allbtn flexs" @click="backlogin">
			退出登录
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			currentSize: ''
		}
	},
	onLoad() {
		// #ifdef APP-PLUS
		this.getStorageSize()
		// #endif
		// wx.setEnableDebug({
		// 	enableDebug: false
		// })
	},
	methods: {
		// #ifdef APP-PLUS
		// 获取本地缓存大小
		getStorageSize() {
			let that = this;
			plus.cache.calculate(function (size) {
				let sizeCache = parseInt(size);
				if (sizeCache == 0) {
					that.currentSize = "0B";
				} else if (sizeCache < 1024) {
					that.currentSize = sizeCache + "B";
				} else if (sizeCache < 1048576) {
					that.currentSize = (sizeCache / 1024).toFixed(2) + "KB";
				} else if (sizeCache < 1073741824) {
					that.currentSize = (sizeCache / 1048576).toFixed(2) + "MB";
				} else {
					that.currentSize = (sizeCache / 1073741824).toFixed(2) + "GB";
				}
			});
		},
		// 清理缓存
		clearStorage() {
			uni.showLoading({
				title: '清理中...',
				mask: true
			})
			let that = this;
			let os = plus.os.name;
			if (os == 'Android') {

				let main = plus.android.runtimeMainActivity();
				let sdRoot = main.getCacheDir();
				let files = plus.android.invoke(sdRoot, "listFiles");
				let len = files.length;
				////console.log(files, len)
				for (let i = 0; i < len; i++) {
					let filePath = '' + files[i]; // 没有找到合适的方法获取路径，这样写可以转成文件路径  
					plus.io.resolveLocalFileSystemURL(filePath, function (entry) {
						if (entry.isDirectory) {
							entry.removeRecursively(function (entry) { //递归删除其下的所有文件及子目录
								that.files = []
								uni.hideLoading()
								uni.showToast({
									title: '清除成功',
									duration: 2000
								});
								that.getStorageSize(); // 重新计算缓存  
							}, function (e) {
								////console.log(e.message)
							});
						} else {
							entry.remove();
						}
					}, function (e) {
						////console.log('文件路径读取失败')
					});
				}
			} else { // ios
				plus.cache.clear(function () {
					uni.hideLoading()
					uni.showToast({
						title: '清除成功',
						duration: 2000
					});
					that.getStorageSize();
				});
			}
		},
		// #endif
		backlogin() {
			uni.clearStorageSync()
			this.$Request.post(this.$api.user.logout).then(res => {
				uni.showToast({
					title: res.msg
				})
				setTimeout(() => {
					// uni.redirectTo({
					// 	url:"/userPage/user/login/register"
					// })
					uni.redirectTo({
						url: "/userPage/user/login/register"
					})
				}, 800)
				clearTimeout();
			});

		},
		gourl(url) {
			uni.navigateTo({
				url: url
			})
		},
		clear() {
			uni.showModal({
				title: '系统提示',
				content: '是否要清理缓存数据（包含前面所设置的信息记录等）',
				success: function (res) {
					if (res.confirm) {
						////console.log('用户点击确定');
					} else if (res.cancel) {
						////console.log('用户点击取消');
					}
				}
			});
		}
	}
}
</script>

<style lang="scss" scoped>
.foot_btn {
	width: 350rpx;
	height: 88rpx;
	background: rgba(0, 0, 0, 0.1);
	box-shadow: inset 0rpx 0rpx 20rpx 0rpx rgba(255, 159, 0, 0.4);
	border-radius: 60rpx 60rpx 60rpx 60rpx;
	opacity: 1;
	border: 1rpx solid #FF9F00;
	margin: auto;
	text-align: center;
	line-height: 88rpx;
	color: #fff;
	margin-top: 150rpx;
}

.real-container {
	width: 100%;
	min-height: 100vh;
	position: relative;
	background: #262626;
}


.business-back-imgbox {
	flex-grow: 1;
}

.business-back {
	width: 48rpx;
	height: 48rpx;
}

.business-title {
	font-size: 36rpx;
	color: white;
	font-weight: 600;
	flex-grow: 1.1;
}

.content {
	width: 96%;
	margin: auto;
	background: #262626;
}

.content .content-item {
	width: 100%;
	min-height: 80rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 20rpx;
	background: rgba(255, 231, 192, 0.1);
	border-radius: 10rpx 10rpx 10rpx 10rpx;
	opacity: 1;
	border: 1rpx solid #FED187;
}

.content .content-item .item-left {
	display: flex;
	justify-content: flex-start;
	align-items: center;
}

.content .content-item .item-left text {
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #fff;
	margin-left: 10rpx
}

.content .content-item .item-text {
	font-size: 28rpx;
	color: #fff;
	opacity: 1;
	margin-right: 20rpx
}
</style>
